package com.gxwy.shenzhou;

public class SelectShouXuFeiRequest implements StringHandler{
	private HeaderRequest header=new HeaderRequest(true);
	private String tran_amt;
	public static final int TRAN_AMT_LEN=15;
	public static final int TRAN_AMT_FLAG=2;
	private String pay_method;
	public static final int PAY_METHOD_LEN=1;
	public static final int PAY_METHOD_FLAG=2;
	private String zone_flag;
	public static final int ZONE_FLAG_LEN=1;
	public static final int ZONE_FLAG_FLAG=2;
	private String corp_flag;
	public static final int CORP_FLAG_LEN=1;
	public static final int CORP_FLAG_FLAG=2;
	public static final int TOTAL_LEN=TRAN_AMT_LEN+PAY_METHOD_LEN+ZONE_FLAG_LEN+CORP_FLAG_LEN;
	private int reallen=0;
	public HeaderRequest getHeader() {
		return header;
	}
	public void setHeader(HeaderRequest header) {
		this.header = header;
	}
	public String getTran_amt() {
		return tran_amt;
	}
	public void setTran_amt(String tran_amt) throws Exception {
		if(tran_amt==null){
			Exception e=new Exception("String is null");
			throw e;
		}else if(tran_amt.getBytes("gbk").length<TRAN_AMT_LEN){
			this.tran_amt=Supply.supply(tran_amt, TRAN_AMT_FLAG, TRAN_AMT_LEN);
		}else if(tran_amt.getBytes("gbk").length>TRAN_AMT_LEN){
			 Exception e=new Exception("Too long");
			 throw e;
		}else{
			this.tran_amt = tran_amt;			
		}
	}
	public String getPay_method() {
		return pay_method;
	}
	public void setPay_method(String pay_method) throws Exception {
		if(pay_method==null){
			Exception e=new Exception("String is null");
			throw e;
		}else if(pay_method.getBytes("gbk").length<PAY_METHOD_LEN){
			this.pay_method=Supply.supply(pay_method, PAY_METHOD_FLAG, PAY_METHOD_LEN);
		}else if(pay_method.getBytes("gbk").length>PAY_METHOD_LEN){
			 Exception e=new Exception("Too long");
			 throw e;
		}else{
			this.pay_method = pay_method;			
		}
	}
	public String getZone_flag() {
		return zone_flag;
	}
	public void setZone_flag(String zone_flag) throws Exception {
		if(zone_flag==null){
			Exception e=new Exception("String is null");
			throw e;
		}else if(zone_flag.getBytes("gbk").length<ZONE_FLAG_LEN){
			this.zone_flag=Supply.supply(zone_flag, ZONE_FLAG_FLAG, ZONE_FLAG_LEN);
		}else if(zone_flag.getBytes("gbk").length>ZONE_FLAG_LEN){
			 Exception e=new Exception("Too long");
			 throw e;
		}else{
			this.zone_flag = zone_flag;			
		}
	}
	public String getCorp_flag() {
		return corp_flag;
	}
	public void setCorp_flag(String corp_flag) throws Exception {
		if(corp_flag==null){
			Exception e=new Exception("String is null");
			throw e;
		}else if(corp_flag.getBytes("gbk").length<CORP_FLAG_LEN){
			this.corp_flag=Supply.supply(corp_flag, CORP_FLAG_FLAG, CORP_FLAG_LEN);
		}else if(corp_flag.getBytes("gbk").length>CORP_FLAG_LEN){
			 Exception e=new Exception("Too long");
			 throw e;
		}else{
			this.corp_flag = corp_flag;			
		}
	}
	public String build() throws Exception{
		if(this.getHeader()==null){
			throw new Exception("Header is null");
		}
		if(this.getTran_amt()==null){
			this.setTran_amt("");
		}
		if(this.getPay_method()==null){
			this.setPay_method("");
		}
		if(this.getZone_flag()==null){
			this.setZone_flag("");
		}
		if(this.getCorp_flag()==null){
			this.setCorp_flag("");
		}
		Integer totallen=header.TOTAL_LEN+TOTAL_LEN-HeaderRequest.LEN_LEN;
		this.getHeader().setLen(totallen.toString());
		return this.getHeader().build()+this.getTran_amt()+this.getPay_method()+this.getZone_flag()+this.getCorp_flag();
	}
	public void parse(String str) throws Exception{
		if(str==null){
			Exception e=new Exception("String is null");
			 throw e;
		}else if(str.getBytes("gbk").length<header.TOTAL_LEN+TOTAL_LEN){
			Exception e=new Exception("Invalid request");
			 throw e;
		}else{
			String headerLen=SplitString.splitString(str,reallen, reallen+header.TOTAL_LEN);
			reallen+=header.TOTAL_LEN;
			header.parse(headerLen);
			this.setTran_amt(SplitString.splitString(str,reallen, reallen+TRAN_AMT_LEN));
			reallen+=TRAN_AMT_LEN;
			this.setPay_method(SplitString.splitString(str,reallen, reallen+PAY_METHOD_LEN));
			reallen+=PAY_METHOD_LEN;
			this.setZone_flag(SplitString.splitString(str,reallen, reallen+ZONE_FLAG_LEN));
			reallen+=ZONE_FLAG_LEN;
			this.setCorp_flag(SplitString.splitString(str,reallen, reallen+CORP_FLAG_LEN));
			reallen+=CORP_FLAG_LEN;
		}
	}
}
